package com.zto.thymeleaf.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zto.thymeleaf.entity.WebDto;

@Controller
public class IndexController {

    @RequestMapping(value="/index")
    public String toIndex(Model model){
        model.addAttribute("msg", "SpringBoot+Thymeleaf");
        model.addAttribute("name", "邢宇超");
        model.addAttribute("age", 23);
        model.addAttribute("sex", "男");
        
        
        List<WebDto> webDtoList = new ArrayList<WebDto>();
        webDtoList.add(new WebDto("CSDN","http://www.csdn.net"));
        webDtoList.add(new WebDto("博客园1", "http://www.cnblogs.com"));
        model.addAttribute("webDtoList", webDtoList);
        return "index";
    }
    
    
    
    @GetMapping(value = "/other")
    public String index(Model model, HttpServletRequest request) {
        List<String> list = new ArrayList<String>();
        list.add("博客园");
        list.add("http://www.cnblogs.com");
        list.add("771326445");
        model.addAttribute("list", list);
        model.addAttribute("curDate", new Date());

        model.addAttribute("money", Math.random()*100);
        return "other";
    }
    
    
    
    @RequestMapping("/zeroException")
    public int zeroException(){
       return 100/0;
    }
    
}
